package com.fhj.movie.adapter;

import com.fhj.movie.entity.JyjTicketListEntity;
import com.fhj.movie_fhj_01.R;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class FilmScheduleAdapter extends BaseAdapter {
	
	private List<JyjTicketListEntity> list;
	private Context context;
	
	
	public void init(Context context,List<JyjTicketListEntity>  list){
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO 自动生成的方法存根
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO 自动生成的方法存根
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO 自动生成的方法存根
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO 自动生成的方法存根
		ViewHolder holder = null;
		if (convertView==null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.movie_details_schedule_listviewitem, parent,false);
			
			holder.starttime = (TextView)convertView.findViewById(R.id.movie_details_listitem_starttime);
			holder.endtime = (TextView)convertView.findViewById(R.id.movie_details_listitem_endtime);
			holder.type = (TextView)convertView.findViewById(R.id.movie_details_listitem_type);
			holder.location = (TextView)convertView.findViewById(R.id.movie_details_listitem_location);
			holder.nowprice = (TextView)convertView.findViewById(R.id.movie_details_listitem_nowprice);
			holder.price = (TextView)convertView.findViewById(R.id.movie_details_listitem_price);
			holder.status = (Button)convertView.findViewById(R.id.movie_details_listitem_status);
			
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		JyjTicketListEntity  entity  = list.get(position);
		holder.starttime.setText(entity.getShowTime().toString());
		holder.endtime.setText(entity.getEndTime()+"结束");
		holder.type.setText(""+entity.getLanguage()+entity.getDimensional());
		holder.location.setText(""+entity.getHallName());
		holder.nowprice.setText(String.valueOf(entity.getPrice()));
		holder.price.setText(String.valueOf(entity.getListPrice()));
		holder.price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		
		if (entity.getStatus()==0) {
			holder.status.setBackgroundColor(Color.GRAY);
			holder.status.setText("无座");
		}else {
			holder.status.setBackgroundColor(Color.rgb(255, 156, 0));
			holder.status.setText("选座");
		}
		
		return convertView;
	}
	
	private class ViewHolder{
	    private	TextView starttime,endtime,type,location,nowprice,price;
	   private Button  status;
	}

}
